using UnityEngine;

[RequireComponent(typeof(PointTrigger_Character))]
public class Door : MonoBehaviour
{
    private PointTrigger_Character trigger;
    private SpriteRenderer spriteRenderer;
    [SerializeField]
    private Sprite sprite_openDoor;
    private Sprite sprite_closeDoor;

    private void Awake()
    {
        trigger = GetComponent<PointTrigger_Character>();
        trigger.OnTriggerEnter += MyOnTriggerEnter;
        trigger.OnTriggerExit += MyOnTriggerExit;
        spriteRenderer = GetComponent<SpriteRenderer>();
        sprite_closeDoor = spriteRenderer.sprite;
    }

    private void MyOnTriggerEnter(Character character)
    {
        spriteRenderer.sprite = sprite_openDoor;
    }

    private void MyOnTriggerExit(Character character)
    {
        spriteRenderer.sprite = sprite_closeDoor;
    }
}
